#include<iostream>
#include<cstdlib>
#include<signal.h>
#include<unistd.h>
using std::cout;
using std::endl;
using std::cerr;
void handler(int signum)
{
    cout<<"Child process has exited,mypid::"<<getpid()<<"Signal num::"<<signum<<endl;
}
int main()
{
    signal(SIGCHLD,handler);
    pid_t id=fork();
    if(id<0)
    {
        cerr<<"fork error!"<<endl;
        exit(1);
    }
    else if(id==0)
    {
        while(true)
        {
            cout<<"I am child process,mypid::"<<getpid()<<endl;
            sleep(2);
        }
        exit(0);
    }
    while(true)
    {
        cout<<"I am parent process!my pid::"<<getpid()<<endl;
        sleep(2);
    }
    return 0;

}
